//
//  titleButton.swift
//  weibo
//
//  Created by 陈经纬 on 16/7/20.
//  Copyright © 2016年 陈经纬. All rights reserved.
//

import UIKit

class titleButton: UIButton {

    //重写framefangfa
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //设置文字在左,图片在右
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder : aDecoder)
        setupUI()
    }
    private func setupUI(){
        //设置图片和名字
        setImage(UIImage(named: "navigationbar_arrow_up"), forState: UIControlState.Normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Selected)
        setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)

        sizeToFit()
    }
    override func setTitle(title: String?, forState state: UIControlState) {
        super.setTitle((title ?? "" ) + "  ", forState: state)
    }
    
    //重写frame的方法,就是重写layoutsubview方法
    override func layoutSubviews() {
        super.layoutSubviews()
        
        imageView?.frame.origin.x = titleLabel!.frame.size.width
        titleLabel?.frame.origin.x = 0
        
        
    }
    
}

